import React, { Component } from "react";
import PropTypes from 'prop-types'
import './index.css'

export default class index extends Component {
  static propTypes = {
    updateCheckAllDone: PropTypes.func.isRequired
  }
  handleCheckAll = (event)=>{
    this.props.updateCheckAllDone(event.target.checked)
  }
  handleClearAllDone = ()=>{
    this.props.clearAllDone()
  }
  render() {
    const {todos} = this.props 
    const doneCount = todos.reduce((pre,todo)=>pre + (todo.done ? 1:0),0)
    const totalCount = todos.length
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" checked={totalCount===doneCount && totalCount !== 0 ? true : false} onChange={this.handleCheckAll}/>
        </label>
        <span>
          <span>已完成0</span> / 全部2
        </span>
        <button className="btn btn-danger" onClick={this.handleClearAllDone}>清除已完成任务</button>
      </div>
    );
  }
}
